<?php
	include("pre.php");

	if( !$_REQUEST['diff_user'] || !$_REQUEST['user_id'] || !$_REQUEST['password'] ){ 
		return false;
	}

	$diff_user_type = $_REQUEST['diff_user'];
	$user_id = $_REQUEST['user_id'];
	$password = $_REQUEST['password'];
	if( $_REQUEST['cCode'] ){ 
		$cCode = $_REQUEST['cCode'];
	}

	$login_snoopy = new Snoopy;
	$login_snoopy->agent = $agent;

	//老师和研究生用青果的服务器IP
	if( $diff_user_type == 'teacher' || $diff_user_type == 'graduate'){
		$login_snoopy->host = IP;
		$submit_url = 'http://".IP."/_data/index_LOGIN.aspx';
		//定义POST内容
		$submit_vars["UserID"] = $user_id;
		$submit_vars["typeName"] = "";
		$submit_vars["Sel_Type"] = "TEA";	//学生为STU,教师为TEA
		$submit_vars["sbtState"] = "";
		$submit_vars["pcInfo"] = "";
		$submit_vars["PassWord"] = $password;
		$submit_vars["cCode"] = $cCode;
		$submit_vars["__VIEWSTATE"] = $_SESSION['VIEWSTATE'];
	}
	//教师
	if( $diff_user_type == 'teacher' ){
		$submit_vars["Sel_Type"] = "TEA";	//学生为STU,教师为TEA
	}
	//研究生
	if( $diff_user_type == 'graduate' ){ 
		$submit_vars["Sel_Type"] = "STU";	//学生为STU,教师为TEA
	}

	$snoopy->referer = $submit_url;
	$snoopy->cookies['ASP.NET_SessionId'] = $_SESSION["ASP_NET_SessionId"];
	$snoopy->cookies['sVC'] = $_SESSION["sVC"];
	//提交
	$snoopy->submit($submit_url,$submit_vars);

	//超时返回
	if ($snoopy->status != '200' || $snoopy->timed_out) {
    	echo json_err(1,"登录提交超时！");
    	break;
	}
	//转码以便查找错误
	$snoopy_results = mb_convert_encoding($snoopy->results, 'utf-8', 'gbk');
	if(stripos($snoopy_results,"密码不正确！")){
    	echo json_err(3,"用户名或密码错误！");
    	break;
	}
	if(stripos($snoopy_results,"验证码错误！")){
    	echo json_err(4,"验证码错误！");
    	break;
	}
	if(stripos($snoopy_results,"页面错误")){
    	echo json_err(5,"session_id错误或超时！");
    	break;
	}
	if(stripos($snoopy_results,"数据库连接失败！")){
    	echo json_err(5,"session_id错误或超时！");
    	break;
	}

	

	//获取姓名学号
	$snoopy_info = new Snoopy;
	//模拟HEADER
	$snoopy_info->cookies['ASP.NET_SessionId'] = $_SESSION["ASP_NET_SessionId"];
	//获取分析表单
	if( $diff_user_type == 'graduate' ){
		
		$snoopy_info->fetch($personurl);
	}
	if( $diff_user_type == 'teacher' ){
		
		$snoopy_info->fetch($personurl_tea);
	}
	$res1 = $snoopy_info->results;

	//超时返回
	if ($snoopy_info->status != '200' || $snoopy_info->timed_out) {
    	echo json_err(1,"页面获取超时！");
    	return;
	}
	//转码以便查找错误
	$snoopy_results = mb_convert_encoding($snoopy_info->results, 'utf-8', 'gbk');
	if(stripos($snoopy_results,"您正查看的此页已过期")){
    	echo json_err(5,"session_id错误或超时！");
    	return;
	}

	
		

?>